package com.yaser.alfresco.model;

import java.io.Serializable;

import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

import com.yaser.util.AlfrescoUtil;

/**
 * @author yasar.yasa
 * 
 */
@XmlRootElement
public class FileList implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4669847195017545907L;

	private String name;
	private String type;
	private String typeShort;
	private String nodeRef;
	private String downloadUrl;
	private String icon32;
	private String parentname;
	private String parentNodeRef;
	private String size;
	private String mimetype;

	@Transient
	private String folderType;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getNodeRef() {
		return nodeRef;
	}

	public void setNodeRef(String nodeRef) {
		this.nodeRef = nodeRef;
	}

	public String getDownloadUrl() {
		if (downloadUrl == null)
			return null;
		else
			return AlfrescoUtil.ALFRESCO_BASE_URL + downloadUrl;
	}

	public void setDownloadUrl(String downloadUrl) {
		this.downloadUrl = downloadUrl;
	}

	public String getIcon32() {
		return AlfrescoUtil.ALFRESCO_BASE_URL + icon32;
	}

	public void setIcon32(String icon32) {
		this.icon32 = icon32;
	}

	public String getParentname() {
		return parentname;
	}

	public void setParentname(String parentname) {
		this.parentname = parentname;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public void setParentNodeRef(String parentNodeRef) {
		this.parentNodeRef = parentNodeRef;
	}

	public String getParentNodeRef() {
		return parentNodeRef;
	}

	public void setTypeShort(String typeShort) {
		this.typeShort = typeShort;
	}

	public String getTypeShort() {
		return typeShort;
	}

	public void setMimetype(String mimetype) {
		this.mimetype = mimetype;
	}

	public String getMimetype() {
		return mimetype;
	}

	public boolean isContainer() {
		if (this.type.contains("folder"))
			return true;
		return false;
	}

	public String findFolderType() {
		String base = "../img/folder-types/";
		
		if (isContainer()) {
			return base + "folder_ful.png";
		} else {
			if (name.contains("jpeg") || name.contains("jpg"))
				return base + "jpg_file.png";
			else if (mimetype.contains("gif"))
				return base + "gif_file.png";
			else if (mimetype.contains("doc"))
				return base + "doc_file.png";
			else if (mimetype.contains("pdf"))
				return base + "pdf_file.png";
			else if (mimetype.contains("xls"))
				return base + "xls_file.png";

		}
		return getIcon32();
	}

	public void setFolderType(String folderType) {
		this.folderType = folderType;
	}

	public String getFolderType() {
		
		String base = "../img/folder-types/";


		if (isContainer()) {
			return base + "folder_full.png";
		} else {
			if (name.substring(name.lastIndexOf(".")).contains("jpeg") || name.substring(name.lastIndexOf(".")).contains("jpg"))
				return base + "jpg_file.png";
			else if (name.substring(name.lastIndexOf(".")).contains("gif"))
				return base + "gif_file.png";
			else if (name.substring(name.lastIndexOf(".")).contains("doc"))
				return base + "doc_file.png";
			else if (name.substring(name.lastIndexOf(".")).contains("pdf"))
				return base + "pdf_file.png";
			else if (name.substring(name.lastIndexOf(".")).contains("xls"))
				return base + "xls_file.png";
			else if (name.substring(name.lastIndexOf(".")).contains("png"))
				return base + "png_file.png";
		}
		
//		
//		if (isContainer()) {
//			return base + "folder_full.png";
//		} else {
//			if (mimetype.contains("jpeg") || mimetype.contains("jpg"))
//				return base + "jpg_file.png";
//			else if (mimetype.contains("gif"))
//				return base + "gif_file.png";
//			else if (mimetype.contains("doc"))
//				return base + "doc_file.png";
//			else if (mimetype.contains("pdf"))
//				return base + "pdf_file.png";
//			else if (mimetype.contains("xls"))
//				return base + "xls_file.png";
//			else if (mimetype.contains("png"))
//				return base + "png_file.png";
//
//		}
		return getIcon32();
	}
}
